import request, { PageQuery, PageResponse } from './request';

// 角色实体
export interface SysRole {
  id?: number;
  roleName: string;
  roleCode: string;
  description: string;
  status: number;
  createTime?: string;
  updateTime?: string;
}

// 分配权限请求
export interface AssignPermissionsRequest {
  roleId: number;
  permissionIds: number[];
}

// 角色管理API
export const roleApi = {
  // 分页查询角色列表
  pageRoles: (params: PageQuery): Promise<PageResponse<SysRole>> => {
    return request.get('/system/role/page', { params });
  },

  // 查询所有角色
  listRoles: (): Promise<SysRole[]> => {
    return request.get('/system/role/list');
  },

  // 根据ID查询角色
  getRole: (id: number): Promise<SysRole> => {
    return request.get(`/system/role/${id}`);
  },

  // 创建角色
  createRole: (data: SysRole): Promise<string> => {
    return request.post('/system/role', data);
  },

  // 更新角色
  updateRole: (data: SysRole): Promise<string> => {
    return request.put('/system/role', data);
  },

  // 删除角色
  deleteRole: (id: number): Promise<string> => {
    return request.delete(`/system/role/${id}`);
  },

  // 分配权限
  assignPermissions: (data: AssignPermissionsRequest): Promise<string> => {
    return request.put('/system/role/assignPermissions', data);
  },

  // 获取角色权限ID列表
  getRolePermissions: (id: number): Promise<number[]> => {
    return request.get(`/system/role/${id}/permissions`);
  },
};